# -*- coding: utf-8 -*-
# @Time    : 19-4-4 下午6:28

import os
import sys

from command import adb as adb_command

sys.path.append(os.path.abspath('..'))


# 获取cpu核数
def get_cpu_kel():
    android_cpu = os.popen(adb_command.get_cpu_core).readlines()
    cpu_kel = int(str(android_cpu[0]).strip(' \n').split('-')[1]) + 1
    return cpu_kel


# 返回 : Android版本
def get_version():
    version_info = os.popen(adb_command.get_version).readlines()[0]
    length = len(version_info)
    if length == 1:
        version_flag = 'P'
    else:
        version_flag = int(str(version_info[0]).strip(' \n').split('.')[0])
    android_version = version_info.split('\n')[0]
    return version_flag, android_version


# 获得手机型号
def get_model():
    model_info = os.popen(adb_command.get_model).readlines()[0].strip('\n\r')
    return model_info


# 获得手机品牌
def get_brand():
    brand_info = os.popen(adb_command.get_brand).readlines()[0].strip('\n\r')
    return brand_info


# 获取API
def get_api():
    api_info = os.popen(adb_command.get_api).readlines()[0]
    android_api = int(api_info)
    return android_api


# 获取设备号
def get_devices_num():
    devices_info = os.popen(adb_command.get_device_num).readlines()[0].strip('\n\r')
    return devices_info


# 获取分辨率
def get_pix():
    pix_info = os.popen(adb_command.get_pix).readlines()[0].strip('\n\r')
    pix = pix_info.split(' ')[2]
    return pix


# 手机基本信息
def get_phone_info():
    model = get_model()
    brand = get_brand()
    pix = get_pix()
    api = get_api()
    version = 'Android ' + get_version()[1].strip('\n\r')
    cpu_kel_num = get_cpu_kel()
    devices_num = get_devices_num()
    phone_basic_info = {'model': model,
                        'brand': brand,
                        'pix': pix,
                        'api': api,
                        'cpu_kel_num': cpu_kel_num,
                        'devices_num': devices_num,
                        'version': version
                        }
    return phone_basic_info
